package com.docted.design.pattern.singleton.serializable;

/**
 * @author DoCted
 * @since v1.0 2018/3/7
 */
public class Serializable implements java.io.Serializable {


    private static final long serialVersionUID = -2670834212153168200L;

    private final static Serializable INSTANCE = new Serializable();

    private Serializable() {
    }

    public static Serializable getInstance() {
        return INSTANCE;
    }


    /**
     * 将单例的对象序列化后再反序列化会出现两个对象
     * 这时候需要重写readResolve()方法
     * 这是Java序列化和反序列化的内部协议
     */
    private Object readResolve() {
        return INSTANCE;
    }
}
